/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const request = require('request-promise');
const iconv = require("iconv-lite");

/**
 * 上海金属网独道
 */
module.exports = class ShanghaiMetalNet extends BaseJsonAdapter {

  async doRequest() {
    var options = {
      method: 'GET',
      uri: this.requestUrl,
      query: {
        currentPage: 1,
        pageSize: 20
      },
      headers: {
        'Content-Type': 'application/json',
        'User-Agent': 'Request-Promise'
      }
    };
    let body = await request(options)
    return body
  }

  async reqJson() {
    let contents = []
    const body = await this.doRequest();
    let res = JSON.parse(body)
    if (res.data && res.data.dataList && res.data.dataList.length) {
      res.data.dataList.forEach(data => {
        contents.push({ title: data.title, href: 'https://www.shmet.com/news/newsDetail.html?version=2&newsId=' + data.newsId })
      })
    }
    return { data: contents };
  }

}
